# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2025, haict

import dash
from dash import html
import dash_bootstrap_components as dbc
import statebar
import menu
import workspace
import templates.index_string as template

def create_app():
    """创建并配置 Dash 应用"""
    app = dash.Dash(
        __name__,
        external_stylesheets=[dbc.themes.BOOTSTRAP],
        suppress_callback_exceptions=True
    )
    app.index_string = template.index_string

    # 注册布局
    app.layout = html.Div(
        [
            statebar.create_layout(),
            menu.create_layout(),
            workspace.create_layout(),
        ],
        style={
            'max-width': '1200px',
            'margin': '0 auto',
            'padding': '20px'
        }
    )

    # 注册所有回调
    register_callbacks(app)
    return app

def register_callbacks(app):
    """注册所有模块的回调"""
    statebar.register_callbacks(app)
    menu.register_callbacks(app)
    workspace.register_callbacks(app)

if __name__ == '__main__':
    app = create_app()
    app.run(host='127.0.0.1', port=9411, debug=True)